package com.healthtop.common;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class HttpMessageResult<T> {

    public static final int DEFAULT_SUCCESS_CODE = 200;

    public static final String DEFAULT_SUCCESS_MESSAGE = "ok";

    public static final int DEFAULT_FAILURE_CODE = 500;

    public static final String DEFAULT_FAILURE_MESSAGE = "fail";



    private T data;

    private int code;

    private String msg;

    private boolean error;


    /**
     * 默认无参成功处理
     * @return
     */
    public static HttpMessageResult success(){
        return HttpMessageResult.builder()
                .code(DEFAULT_SUCCESS_CODE)
                .msg(DEFAULT_SUCCESS_MESSAGE)
                .error(Boolean.FALSE)
                .build();
    }

    /**
     * 默认无参失败处理
     * @return
     */
    public static HttpMessageResult failure(){
        return HttpMessageResult.builder()
                .code(DEFAULT_FAILURE_CODE)
                .msg(DEFAULT_FAILURE_MESSAGE)
                .error(Boolean.TRUE)
                .build();
    }

    public static HttpMessageResult failure(String message, int code){
        return HttpMessageResult.builder()
                .code(code)
                .msg(message)
                .error(Boolean.TRUE)
                .build();
    }

    public static <T> HttpMessageResult success(T data){
        return HttpMessageResult.builder()
                .code(DEFAULT_SUCCESS_CODE)
                .msg(DEFAULT_SUCCESS_MESSAGE)
                .data(data)
                .error(Boolean.FALSE)
                .build();
    }

    public static <T> HttpMessageResult success(T data, String message, int code){
        return HttpMessageResult.builder()
                .code(code)
                .msg(message)
                .data(data)
                .error(Boolean.FALSE)
                .build();
    }

    public static HttpMessageResult success(String message, int code){
        return HttpMessageResult.builder()
                .code(code)
                .msg(message)
                .error(Boolean.FALSE)
                .build();
    }

}
